//443. 压缩字符串
class Solution {
public:
    int compress(vector<char>& chars) {
        vector<char> res;
        stack<char> st;
        if(chars.size()==1)
        {
            return 1;
        }

        int j=1; //控制字符长度
        int next=1;
        
        for(int i=0;i<chars.size();)
        {
            while(next<chars.size() &&chars[i]==chars[next]  )
            {
                j++;
                next++;
            }         
            res.push_back(chars[i]); 
            if(j>1)
            {
                while(j)
                {
                    st.push(char(j%10)+'0');
                    j/=10;
                
                }

            }

            while(!st.empty())
            {
                res.push_back(st.top());
                st.pop();
            }
            i=next;
            next=next+1;
            j=1;
        }
    int p = res.size();
    chars.swap(res);
    return p;

    }
};